﻿using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
using Pigg.Data.Configurations;
using Pigg.Model;

namespace Pigg.Data
{
    public class PiggDbContext : DbContext 
    {
        static PiggDbContext()
        {
            Database.SetInitializer<PiggDbContext>(null);
        }
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            // Use singular table names
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();

            // Disable proxy creation and lazy loading; not wanted in this service context.
            Configuration.ProxyCreationEnabled = false;
            Configuration.LazyLoadingEnabled = false;
            
            modelBuilder.Configurations.Add(new AuthPermissionConfiguration());
            modelBuilder.Configurations.Add(new AuthRoleConfiguration());
            modelBuilder.Configurations.Add(new ContentItemConfiguration());
            modelBuilder.Configurations.Add(new ContentListConfiguration());
            modelBuilder.Configurations.Add(new ContentPageConfiguration());
            modelBuilder.Configurations.Add(new ImageContentConfiguration());
            modelBuilder.Configurations.Add(new ImageListConfiguration());
            modelBuilder.Configurations.Add(new MenuContainerConfiguration());
            modelBuilder.Configurations.Add(new MenuItemConfiguration());
            modelBuilder.Configurations.Add(new PersonConfiguration());
        }

        public DbSet<ContentItem> ContentItems { get; set; }
        public DbSet<ContentList> ContentLists { get; set; }
        public DbSet<ImageContent> ImageContents { get; set; }
        public DbSet<ImageList> ImageLists { get; set; }
        public DbSet<MenuContainer> MenuContainers { get; set; }
        public DbSet<MenuItem> MenuItems { get; set; }
        public DbSet<ContentPage> ContentPages { get; set; }
        public DbSet<AuthPermission> AuthPermissions { get; set; }
        public DbSet<AuthRole> AuthRoles { get; set; }
        public DbSet<Person> People { get; set; }
    }
}
